package org.agle4j.algorithm.array.unordered;

public class OperateWithIndex {
	private int[] datas = null;
	private int currentIndex = 0;

	public OperateWithIndex(int length) {
		this.datas = new int[length];
	}

	public OperateWithIndex(int[] datas) {
		this.datas = datas;
		this.currentIndex = (datas.length - 1);
	}

	public int insert(int data) {
		this.datas[this.currentIndex] = data;
		this.currentIndex += 1;
		return this.currentIndex - 1;
	}

	public void remove(int index) {
		for (int i = index; i < this.currentIndex; i++) {
			this.datas[i] = this.datas[(i + 1)];
		}
		this.currentIndex -= 1;
	}

	public int searchOne(int index) {
		return this.datas[index];
	}

	public void printDatas() {
		for (int i = 0; i < this.currentIndex; i++) {
			System.out.println(this.datas[i]);
		}
		System.out.println();
	}
}
